package com.security.service.impl;

import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class UserDetailsServiceImpl implements UserDetailsService {

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        // 临时使用内存中的测试用户
        if ("admin".equals(username)) {
            return User.withUsername("admin")
                    .password("{noop}admin123") // {noop}表示使用明文密码，仅用于测试
                    .roles("ADMIN")
                    .build();
        }
        throw new UsernameNotFoundException("User not found with username: " + username);
    }
}